package pta06;

import java.util.Arrays;


@SuppressWarnings("hiding")
interface IntegerStack<Integer>{
	public Integer push(Integer item) throws FullStackException;
	public Integer pop() throws EmptyStackException; 
	public Integer peek() throws EmptyStackException; 
	public boolean empty(); 
	public int size(); 
}
class FullStackException extends Exception {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public FullStackException() throws FullStackException {
		super();
	}

}
class EmptyStackException extends Exception {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public EmptyStackException() throws EmptyStackException {
		super();
	}

}
class ArrayIntegerStack implements IntegerStack<Integer>{
	private int capacity=0;;
	private int top=0;
	private Integer[] arrStack;
	public ArrayIntegerStack(int size){
		this.capacity=size;
		this.arrStack=new Integer[size];
	}
	public Integer push(Integer item) throws FullStackException{
		//濡傛灉item涓簄ull锛屽垯涓嶅叆鏍堢洿鎺ヨ繑鍥瀗ull銆傚鏋滄爤婊★紝涔熻繑鍥瀗ull銆傚鏋滄彃鍏ユ垚鍔燂紝杩斿洖item銆�
		if(capacity<=top){
			throw new FullStackException();
		}
		if(item==null){
			return null;	
		}
		else {
    			arrStack[top++]=item;
			return item;
		}
 	}
	public Integer pop() throws EmptyStackException{
		//鍑烘爤锛屽鏋滀负绌猴紝鍒欒繑鍥瀗ull銆傚嚭鏍堟椂鍙Щ鍔ㄦ爤椤舵寚閽堬紝鐩稿簲浣嶇疆涓嶇疆涓簄ull
		if(empty()){
		     throw new EmptyStackException();
		}
		else {
		  	Integer elem=arrStack[--top];
			return elem;
			
		}
        }
	public Integer peek() throws EmptyStackException{
		//鑾峰緱鏍堥《鍏冪礌锛屽鏋滀负绌猴紝鍒欒繑鍥瀗ull.
		if(empty()){
		     throw new EmptyStackException();
		}
		else {
			return arrStack[top-1];
	    }
	}
	public boolean empty(){
		//濡傛灉涓虹┖杩斿洖true
		if(top==0){
		  return true;
		}
		else return false;
	}
	public int size(){
		//杩斿洖鏍堜腑鍏冪礌涓暟
	   return top;
	}
	
	public String toString() {
		return  Arrays.toString(arrStack);
	}	
	
}

public class pta643 {
	public static void main(String[] args){
	
	}
}
